//
//  QRController.m
//  SSC
//
//  Created by 红沙尘 on 17/6/26.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "QRController.h"
#import "SGQRCode.h"
@interface QRController ()
{
    __weak IBOutlet UIImageView *QRView;
}

@property (nonatomic, assign) QRType type;

@end

@implementation QRController

- (id)initWithQRType:(QRType)type {
    
    self = [super init];
    
    if (self) {
        self.type = type;
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString *sys = @"1";
    
    if (self.type == QRTypeApple) {
//        QRView.image = LoadImage(@"AppleQR");
        [self setTitle:@"下载苹果手机APP"];
        sys = @"1";
    } else if (self.type == QRTypeAndroid) {
//        QRView.image = LoadImage(@"AndroidQR");
        [self setTitle:@"下载安卓手机APP"];
        sys = @"0";
    }
    
    [LoadingView show];
    
    [SSCRequest appUpdateWithSystem:sys
                            success:^(NSDictionary *responseObject)
     {
         [LoadingView diss];
         NSLog(@"responseObject = %@",responseObject);

         NSDictionary *data = responseObject[@"data"];
        
         NSString *url = [NSString safeString:data[@"url"]];
         
         QRView.image = [SGQRCodeGenerateManager SG_generateWithDefaultQRCodeData:url
                                                                   imageViewWidth:ScreenWidth];
         
    } fail:^(NSError *error) {
        [LoadingView diss];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
